Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: base impl for ecs fargate cdk #371

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gabedos
Copy link
Collaborator

@gabedos gabedos commented Feb 24, 2025

What does this PR do?

This creates the base implementation for the Datadog ECS Fargate CDK. This includes features such as:

  • DD_API_KEY from AWS Secrets Manager handling
  • Log configuration via Fluentbit
  • APM / DogStatsd configuration via TCP/UDP and UDS
  • Windows configuration
  • Cloud Workload Security (CWS) configuration

Motivation

Allow ECS Fargate customers to easily instrument their applications to properly run Datadog features.

Testing Guidelines

Tests TBD on general feedback. Otherwise tests will be created for each and every method to ensure they properly augment the container definitions properly.

Additional Notes

Types of Changes

  • Bug fix
  • New feature
  • Breaking change
  • Misc (docs, refactoring, dependency upgrade, etc.)

Check all that apply

  • This PR's description is comprehensive
  • This PR contains breaking changes that are documented in the description
  • This PR introduces new APIs or parameters that are documented and unlikely to change in the foreseeable future
  • This PR impacts documentation, and it has been updated (or a ticket has been logged)
  • This PR's changes are covered by the automated tests
  • This PR collects user input/sensitive content into Datadog

* Enables Dogstatsd traffic over Unix Domain Socket.
* Falls back to UDP configuration for application containers when disabled
*/
readonly enableDogstatsdSocket?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Prop name (enableDogstatsdSocket) doesn't match rule (is|has) (...read more)

Enforces a consistent naming pattern for boolean props.

The pattern is: "^(is|has)[A-Z]([A-Za-z0-9]?)+" to enforce is and has prefixes.

View in Datadog  Leave us feedback  Documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into prefixing these bools with "is"
Might also change the configuration for each feature to have their own sub-interfaces too.


// CWS Configuration:
if (props.enableCWS) {
const containerProps = (container as any).props as ecs.ContainerDefinitionProps;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation


const currentEntryPoint = containerProps.entryPoint as string[];
currentEntryPoint.unshift(...entryPointPrefixCWS);
(container as any).props.entryPoint = currentEntryPoint;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for opinions on this. I need to access a few values in the container such as linuxParameters, entryPoint, etc. to properly configure Datadog. However, many of these are private and/or readonly.

I've tried getting the cfn definition of the task/container when possible to retrieve the values more safely, but some seem to be just impossible to do safely and requires the (as any).

(container as any).props.entryPoint = currentEntryPoint;

if (container.linuxParameters === undefined) {
(container as any).linuxParameters = new ecs.LinuxParameters(this.scope, "LinuxParameters", {});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Code Quality Violation

Unsafe assignment of an `any` value. (...read more)

The any type in TypeScript is dangerously broad, leading to unexpected behavior. Using any should be avoided.

View in Datadog  Leave us feedback  Documentation

Copy link
Contributor

@lym953 lym953 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A suggestion based on my preference: For future PRs, is it possible to keep each PR small, maybe no more than 100 lines of code (not including tests)? Thus it's more clear what each PR does, makes it more clear which test is for which code, making review easier. Examples: https://github.com/DataDog/datadog-cloudformation-macro/pulls?q=is%3Apr+is%3Aclosed+%5BStep+Function%5D

src/index.ts Outdated
Comment on lines 22 to 26
export * from "./ecs/interfaces";
export * from "./ecs/constants";
export * from "./ecs/fargate/interfaces";
export * from "./ecs/environment";
export * from "./ecs/utils";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete these lines? I think ideally we should only export these files:

export * from "./datadog-lambda";
export * from "./datadog-step-functions";
export * from "./ecs/fargate/datadog-ecs-fargate";

and in these files, only expose those functions that are intended to be external API functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree we should only expose the Construct + Props externally. I can make edits to support this.

@lym953
Copy link
Contributor

lym953 commented Feb 24, 2025

Thanks for creating the ecs/ folder! I think my team can also consider moving the Lambda / Step Function files to a folder. If that is a breaking change, we can make it part of the next major version bump.

@gabedos
Copy link
Collaborator Author

gabedos commented Feb 25, 2025

A suggestion based on my preference: For future PRs, is it possible to keep each PR small, maybe no more than 100 lines of code (not including tests)? Thus it's more clear what each PR does, makes it more clear which test is for which code, making review easier. Examples: https://github.com/DataDog/datadog-cloudformation-macro/pulls?q=is%3Apr+is%3Aclosed+%5BStep+Function%5D

Sorry I got a bit carried away after having an MVP and started adding features like APM, DSD, Logs to test it out. In the future they will definitely be smaller!

@gabedos gabedos changed the title Base impl for ecs fargate cdk feat: base impl for ecs fargate cdk Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants